﻿/**
* @file stepper_motor.c
* @brief this is a brief description
* @details this is the detail description.
* @author fulong 
* @data 2014/10/15
* @version 1.0
* @par Copyright (c):
* @par First build
*     version: fulong 
*     data: 2014/10/15
*/
#include "stepper_motor.h"
#include "../dev/io_configure.h"
#include "../dev/timer.h"
#define  FREQ_TAB_LEN 100
uint8 fre_index = 0;
const uint16 FreqTab[FREQ_TAB_LEN] = { 11059, 9216, 7899, 6912, 6144, 5529, 5026, 4608, 4253, 3949, 3686,
    3456, 3252, 3072, 2910, 2764, 2633, 2513, 2404, 2304, 2211, 2168,
    2126, 2086, 2048, 2010, 1974, 1940, 1906, 1874, 1843, 1812, 1783,
    1755, 1728, 1701, 1675, 1650, 1626, 1602, 1579, 1557, 1536, 1514,
    1494, 1474, 1455, 1436, 1417, 1399, 1382, 1365, 1348, 1332, 1316,
    1301, 1285, 1271, 1256, 1242, 1228, 1215, 1202, 1189, 1176, 1164,
    1152, 1140, 1128, 1117, 1105, 1094, 1084, 1073, 1063, 1053, 1043,
    1033, 1024, 1014, 1005, 996, 987, 978, 970, 961, 953, 945, 937, 929,
    921, 913, 906, 899, 891, 884, 877, 870, 864, 857 //12.9k
};

void change_dr2(uint8 data)
{
#ifdef __XT14012__
#ifdef V1_4
    if (data)
    {
        set_output_value(2, 5);
    } else
    {
        clr_output_value(2, 5);
    }
#endif
#endif
}
void change_dr3(uint8 data)
{
#ifdef __XT14012__
#ifdef V1_4
    if (data)
    {
        set_output_value(5, 2);
    } else
    {
        clr_output_value(5, 2);
    }
#endif
#endif
}
void change_dr1(uint8 data)
{
#ifdef __XT14012__
#ifdef V1_4
    if (data)
    {
        set_output_value(8, 3);
    } else
    {
        clr_output_value(8, 3);
    }
#endif
#endif
}
void change_mf1(uint8 data)
{
//  if (data) {
//      set_output_value(6, 6);
//  } else {
//      clr_output_value(6, 6);
//  }
}
void change_mf2(uint8 data)
{
//  if (data) {
//      set_output_value(6, 5);
//  } else {
//      clr_output_value(6, 5);
//  }
}

void stepper_motor_init(void)
{
#ifdef __XT14012__
#ifdef V1_4
    set_output(8, 3);
    set_output(2, 5);
    set_output(5, 2);
    set_output(3, 0);
#ifdef __BOARD_TEST__
    clr_output_value(3, 0);
#endif
#endif
#endif
//  SETDR();
    ClosePWM();
}
void stepper_motor_speed_up(void)
{
    ClosePWM();
    set_pwm_trd1(FreqTab[fre_index]);
    OpenPWM();
//  fre_index++;
}

